﻿package com.wly.adapter
{
	import com.wly.adapter.common.AdapterBase;
	import com.wly.ui.MapEditerMain;
	import com.wly.ui.Status;
	
	import flash.display.BitmapData;
	
	public class MapEditerMainAdapter extends AdapterBase
	{
		private var _itemGridAdapter:ItemGridAdapter;
		private var _toolbarAdapter:ToolbarAdapter;
		private var _mapAreaAdapter:MapAreaAdapter;
		static private var _CURBMD:BitmapData;
		static public var MAPINDEX:int = 0;
		
		public function MapEditerMainAdapter()
		{
			super();
			init();
		}
		
		private function init():void
		{
			_toolbarAdapter = new ToolbarAdapter();
			_mapAreaAdapter = new MapAreaAdapter();
		}
		
		protected function get uiMapEditerMain():MapEditerMain
		{
			return ui as MapEditerMain;
		}
		
		override protected function onUIAttach():void
		{
			if(uiMapEditerMain)
			{
				uiMapEditerMain.updateToolbar(_toolbarAdapter);
				uiMapEditerMain.updateMapAreaAdapter(_mapAreaAdapter);
			}
		}
		
		static public function set CURBMD(bmd:BitmapData):void
		{
			_CURBMD = bmd;
			Status.getInstance().updateItem(_CURBMD);
		}
		
		static public function get CURBMD():BitmapData
		{
			return _CURBMD;
		}
		
		public function update():void
		{
			var i:int;
			var bmd:BitmapData;
			var bmdArr:Array;
			var color:uint;
			
			bmdArr = [];
			for(i=0; i<15; i++)
			{
				if(i%2)
				{
					bmd = new ItemBmd1;
				}
				else
				{
					bmd = new ItemBmd2;
				}
				bmdArr.push(bmd);
			}
			_toolbarAdapter.updateData(bmdArr);
		}
		
		public function switchWorkStat():void
		{
			_mapAreaAdapter.switchWorkStat();
		}
		
		public function setRoadInfo():void
		{
			if(uiMapEditerMain)
			{
				uiMapEditerMain.roadInfo = _mapAreaAdapter.roadStr;
			}
		}
	}
}